/** bcmi_frame job interface
 *
 *  bcmi_frame job interface
 *
 *  @author : huicong
 *  @date : 2008-10-29
 *
 */

#ifndef _FRAME_JOB_H
#define _FRAME_JOB_H

#include "BasicHeader.h"
#include "ParallelFrame.h"
#include "JobSystem.h"
#include "FrameTask.h"
#include "DefaultNullTask.h"

#include <string>
#include <map>
#include <vector>

namespace bcmi_frame
{

    /** //UNDO
     *
     *
     *
     */
    VIRTUAL_CLASS class FrameJob
    {
    public:
        typedef std::map<STRING, FrameTask*> TASK_MAP;
        typedef std::vector<FrameTask*> TASK_LIST;

    public:

        FrameJob();

        ~FrameJob();

    public:

        /** Link the scheduler */
        virtual VOID linkFrame(_IN ParallelFrame *_frame);

        virtual ParallelFrame* getFrame();

        /** return JobName */
        virtual CSTRING jobName() const;

        /** Register user task in this Job
         *
         *  Register user task in this Job. This task will be destroyed by this Job,
         *  so user must not be let this task wrong before job finished.
         *
         *  @param [IN] STRING _regName : the name of the task instance
         *                   "___bcmi_frame_initailize_task__" must not be used        
         *                   "___bcmi_frame_finalize_task__" must not be used
         *  @param [INOUT] FrameTask *_task : binding task
         *
         */
        HRESULT taskRegister(IN STRING _regName, INOUT FrameTask *_task);

        /** job MAIN FUNCTION */
        virtual HRESULT execute() = 0;

        /** taskRegister(___FRAME_INI_TASK_NAME, _task) */
        HRESULT registerInitializeTask(INOUT FrameTask *_task);

        /** taskRegister(___FRAME_FIN_TASK_NAME, _task) */
        HRESULT registerFinalizeTask(INOUT FrameTask *_task);

    protected:

        VOID setDefaultInitializeTask();

        VOID setDefaultFinalizeTask();

        virtual HRESULT executeTask(INOUT FrameTask* _task) = 0;

        virtual HRESULT initializeTask(INOUT FrameTask* _task) = 0;

        virtual HRESULT finalizeTask(INOUT FrameTask* _task) = 0;

    protected:
        ParallelFrame *_myFrame;
        UINT _taskIdCount;
        TASK_MAP _taskMap;
        TASK_LIST _taskList;
    };

}; //namespace bcmi_frame

#endif //#ifndef _FRAME_JOB_H